<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:c="http://java.sun.com/jsp/jstl/core">

    <ui:composition template="/resource/template/plantilla.xhtml">

        <!--Segmento que define el contenido del header-->
        <ui:define name="head">
            <h:head>
                <f:loadBundle basename="person.schedule.label_#{logged.loggedIdiom}" var="label" />
                <f:loadBundle basename="person.schedule.message_#{logged.loggedIdiom}" var="message" />
                <f:loadBundle basename="person.schedule.help_#{logged.loggedIdiom}" var="help" />   
                <script src="../../../resource/js/jquery.maskedinput-1.3.js" type="text/javascript"></script>
                <script>
                    $(document).ready(function() {

                        $.mask.definitions['H'] = '[012]';
                        $.mask.definitions['h'] = '[0123456789]';
                        $.mask.definitions['N'] = '[012345]';
                        $.mask.definitions['n'] = '[0123456789]';
                        $(".horaentrada").mask("Hh:Nn");
                        $(".horasalida").mask("Hh:Nn");
                    });
                </script>
                <script>
                    $(function() {
                        $("#form1\\:university").mousedown(function() {
                            $("#form1\\:universitybased").val("0");
                        });
                    });
                </script>
                <script>
                    function validarentrada(valor)
                    {
                        //que no existan elementos sin escribir
                        if (valor.indexOf("_") == -1)
                        {
                            var hora = valor.split(":")[0];
                            if (parseInt(hora) > 23)
                            {
                                $("#horaentrada").val("");
                            }
                        }
                    }

                </script>
                <script>
                    function validarsalida(valor)
                    {
                        //que no existan elementos sin escribir
                        if (valor.indexOf("_") == -1)
                        {
                            var hora = valor.split(":")[0];
                            if (parseInt(hora) > 23)
                            {
                                $("#horasalida").val("");
                            }
                        }
                    }

                </script>
                <script>
                    function verificar(dato)
                    {
                        var agree = confirm(dato);
                        if (agree)
                            return true;
                        else
                            return false;
                    }
                </script>
            </h:head>
        </ui:define>

        <!--Segmento que define el contenido de la pagina-->
        <ui:define name="content">
            <h:body>
                <h:outputText value="#{message.m0}" class="label" rendered="#{!access.visit}"/>
                <h:form rendered="#{access.visit}">   
                    <p:growl id="messages" showDetail="true"/>  
                    <div class="field">
                        <h:outputText value="#{label.field3}" class="label"/>
                        <p:calendar  id="periodoinicial" value="#{person_schedule.periodoinicial}" effect="slide" navigator="true" readonlyInput="true" pattern="dd/MM/yy" size="5"/>
                        <h:outputText class="required" value="*"/>
                    </div>
                    <div class="field"> 
                        <h:outputText value="#{label.field4}" class="label"/>
                        <p:calendar id="periodofinal"  value="#{person_schedule.periodofinal}" effect="slide"   navigator="true" readonlyInput="true" pattern="dd/MM/yy" size="5"/>               
                        <h:commandButton value="#{label.button5}" actionListener="#{person_schedule.find}" class="button"/>
                        <h:outputText class="required" value="*"/>
                    </div>
                    <div class="field">
                        <h:outputText value="#{label.field5}" class="label"/>
                        <h:selectOneMenu value="#{person_schedule.idl_dia}">  
                            <f:selectItem itemLabel="#{label.dia1}" itemValue="1"/> 
                            <f:selectItem itemLabel="#{label.dia2}" itemValue="2"/> 
                            <f:selectItem itemLabel="#{label.dia3}" itemValue="3"/> 
                            <f:selectItem itemLabel="#{label.dia4}" itemValue="4"/>
                            <f:selectItem itemLabel="#{label.dia5}" itemValue="5"/> 
                            <f:selectItem itemLabel="#{label.dia6}" itemValue="6"/> 
                            <f:selectItem itemLabel="#{label.dia7}" itemValue="7"/> 
                        </h:selectOneMenu>
                        <h:outputText class="required" value="*"/>
                    </div>
                    <div class="field">
                        <h:outputText value="#{label.field6}" class="label"/> 
                        <h:inputText class="horaentrada textfield" value="#{person_schedule.horaentrada}"
                                     required="#{param['required']=='true'}" requiredMessage="#{message.m28}"
                                     onblur="validarentrada(this.value)" 
                                     size="3"/>
                        <h:outputText class="required" value="*"/>
                    </div>
                    <div class="field">
                        <h:outputText value="#{label.field7}" class="label"/> 
                        <h:inputText class="horasalida textfield" value="#{person_schedule.horasalida}"
                                     required="#{param['required']=='true'}" requiredMessage="#{message.m29}"
                                     onblur="validarsalida(this.value)"
                                     size="3"/>  
                        <h:outputText class="required" value="*"/>
                    </div>

                    <div class="field">
                        <h:outputText value="#{label.field11}" class="label"/> 
                        <h:selectOneMenu id="university" value="#{person_schedule.universityBeans.id}" valueChangeListener="#{person_schedule.selectedUniversity}" onchange="submit()" >
                            <f:selectItem itemLabel="" itemValue="0"/>
                            <f:selectItems value="#{university_generalFind.listItem()}"/>  
                        </h:selectOneMenu> 
                        <h:outputText class="required" value="*"/>
                    </div>
                    <div class="field">
                        <h:outputText value="#{label.field9}" class="label"/> 
                        <h:selectOneMenu id="universitybased" value="#{person_schedule.id_sede}" valueChangeListener="#{person_schedule.selectedUniversity_based}" 
                                         required="#{param['required']=='true'}" requiredMessage="#{message.m23}">
                            <f:selectItem itemLabel="" itemValue="0"/>
                            <f:selectItems value="#{university_locationFind.listItem(person_schedule.universityBeans.id)}"/>  
                        </h:selectOneMenu>
                        <h:outputText class="required" value="*"/>
                    </div>

                    <div class="field">
                        <h:outputText value="#{label.field8}" class="label"/> 
                        <h:selectOneMenu id="asignatura" value="#{person_schedule.id_persona_asignatura}" valueChangeListener="#{person_schedule.selectedAsignatura}" onchange="submit()" >
                            <f:selectItem itemLabel="" itemValue="0"/>
                            <f:selectItems value="#{person_asignatureFind.listItem()}"/>  
                        </h:selectOneMenu> 
                        <h:outputText class="required" value="*"/>
                    </div>

                    <div class="field">
                        <h:outputText value="#{label.field10}" class="label"/>
                        <h:inputText id="aula" class="textfield" value="#{person_schedule.aula}"
                                     required="#{param['required']=='true'}" requiredMessage="#{message.m27}"
                                     size="25" maxlength="20"
                                     />
                        <h:outputText class="required" value="*"/>
                    </div>
                    <h:commandButton value="#{label.button1}" actionListener="#{person_schedule.insert}" class="button" onclick="return verificar('#{message.m7}')">
                        <f:param name="required" value="true"/>
                    </h:commandButton>
                    <h:commandButton value="#{label.button2}" actionListener="#{person_schedule.update}" class="button" onclick="return verificar('#{message.m8}')">
                        <f:param name="required" value="true"/>
                    </h:commandButton>
                    <h:commandButton value="#{label.button3}" actionListener="#{person_schedule.delete}" class="button" onclick="return verificar('#{message.m9}')"/>
                    <h:commandButton value="#{label.button4}" actionListener="#{person_schedule.clear}" class="button"/>
                </h:form>
                <h:form id="formcalendar">
                    <c:set var="list" value="#{person_scheduleFind.listByLoggedMap}"/>
                    <h:panelGroup layout="block" class="tableWrapper" rendered="#{not empty list}">
                        <h:dataTable var="p" value="#{list}"  class="dataTable">  
                            <h:column>
                                <f:facet name="header">#{label.field}</f:facet>
                                <h:commandLink styleClass="editButton" actionListener="#{person_schedule.selectedRecordId(p.id)}" />
                            </h:column>
                            <h:column>
                                <f:facet name="header"   >#{label.field3}</f:facet>  
                                <h:outputText value="  #{p.periodoinicial}  "/>
                            </h:column>
                            <h:column>
                                <f:facet name="header">#{label.field4}</f:facet>  
                                <h:outputText value="  #{p.periodofinal}  "/>
                            </h:column>
                            <h:column>
                                <f:facet name="header">#{label.field5}</f:facet>
                                <c:set var="dia" value="dia#{p.idl_dia}" />
                                <h:outputText value="#{label[dia]}"/>
                            </h:column>
                            <h:column>
                                <f:facet name="header">#{label.field6}</f:facet>  
                                <h:outputText value=" #{p.horaentrada}  "/>
                            </h:column>  
                            <h:column>
                                <f:facet name="header">#{label.field7}</f:facet>  
                                <h:outputText value="  #{p.horasalida}  "/>
                            </h:column>
                            <h:column>
                                <f:facet name="header">#{label.field10}</f:facet>  
                                <h:outputText value="  #{p.aula}  "/>
                            </h:column>
                            <h:column>
                                <f:facet name="header">#{label.field8}</f:facet>
                                <h:outputText value="#{p.docente_asignatureBeans.nombre} - #{p.university_locationBeans.nombre}"/>
                            </h:column>
                        </h:dataTable>
                    </h:panelGroup>
                </h:form>
            </h:body>
        </ui:define>

        <!--Segemento donde se define un texto de ayuda para que el usuario pueda utilizar el formulario del contenido-->
        <ui:define name="slideHelper">
            <h3>#{help.title1} </h3>
            #{help.detail1a}
            <p>
                #{help.title2}
                <ul>
                    <li>#{help.detail2a}</li>
                </ul> 
                #{help.title4}
                <ul>
                    <li>#{help.detail4a}</li>
                </ul> 
                #{help.title3}
                <ul>
                    <li>#{help.detail3a}</li>
                    <li>#{help.detail3b}</li>
                    <li>#{help.detail3c}</li>
                    <li>#{help.detail3d}</li>
                    <li>#{help.detail3e}</li>

                </ul>
            </p>

        </ui:define>
    </ui:composition>
</html>
